package com.iris.nio;

import java.io.*;
import java.nio.channels.FileChannel;
import java.util.UUID;

public class FileChannelTransfer {
    public static void main(String[] args) throws IOException {
        String path = BufferTest.class.getResource("/").getPath()+"com/iris/nio/ifyou.txt";
        System.out.println(path);
        path=path.substring(1,path.length());
        System.out.println(path);
        FileInputStream input =new FileInputStream(path);
        FileChannel inputChannel = input.getChannel();
        File file = new File("D:/"+ UUID.randomUUID()+".txt");
        if(!file.exists()){
            file.createNewFile();
        }
        FileOutputStream output = new FileOutputStream(file);
        FileChannel outputChannel = output.getChannel();
        outputChannel.transferFrom(inputChannel,0,inputChannel.size());
        outputChannel.close();
        inputChannel.close();
        input.close();
        output.close();
    }
}
